<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>advancedtooltip.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_advancedtooltip.js.html">advancedtooltip.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Advanced tooltip widget implementation.
<a name="line17"></a> *
<a name="line18"></a> * @author eae@google.com (Emil A Eklund)
<a name="line19"></a> * @see ../demos/advancedtooltip.html
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.ui.AdvancedTooltip&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.events&#39;);
<a name="line25"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line26"></a>goog.require(&#39;goog.math.Box&#39;);
<a name="line27"></a>goog.require(&#39;goog.math.Coordinate&#39;);
<a name="line28"></a>goog.require(&#39;goog.style&#39;);
<a name="line29"></a>goog.require(&#39;goog.ui.Tooltip&#39;);
<a name="line30"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * Advanced tooltip widget with cursor tracking abilities. Works like a regular
<a name="line36"></a> * tooltip but can track the cursor position and direction to determine if the
<a name="line37"></a> * tooltip should be dismissed or remain open.
<a name="line38"></a> *
<a name="line39"></a> * @param {Element|string=} opt_el Element to display tooltip for, either
<a name="line40"></a> *     element reference or string id.
<a name="line41"></a> * @param {?string=} opt_str Text message to display in tooltip.
<a name="line42"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line43"></a> * @constructor
<a name="line44"></a> * @extends {goog.ui.Tooltip}
<a name="line45"></a> */
<a name="line46"></a>goog.ui.AdvancedTooltip = function(opt_el, opt_str, opt_domHelper) {
<a name="line47"></a>  goog.ui.Tooltip.call(this, opt_el, opt_str, opt_domHelper);
<a name="line48"></a>};
<a name="line49"></a>goog.inherits(goog.ui.AdvancedTooltip, goog.ui.Tooltip);
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * Whether to track the cursor and thereby close the tooltip if it moves away
<a name="line54"></a> * from the tooltip and keep it open if it moves towards it.
<a name="line55"></a> *
<a name="line56"></a> * @type {boolean}
<a name="line57"></a> * @private
<a name="line58"></a> */
<a name="line59"></a>goog.ui.AdvancedTooltip.prototype.cursorTracking_ = false;
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>/**
<a name="line63"></a> * Delay in milliseconds before tooltips are hidden if cursor tracking is
<a name="line64"></a> * enabled and the cursor is moving away from the tooltip.
<a name="line65"></a> *
<a name="line66"></a> * @type {number}
<a name="line67"></a> * @private
<a name="line68"></a> */
<a name="line69"></a>goog.ui.AdvancedTooltip.prototype.cursorTrackingHideDelayMs_ = 100;
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * Box object representing a margin around the tooltip where the cursor is
<a name="line74"></a> * allowed without dismissing the tooltip.
<a name="line75"></a> *
<a name="line76"></a> * @type {goog.math.Box}
<a name="line77"></a> * @private
<a name="line78"></a> */
<a name="line79"></a>goog.ui.AdvancedTooltip.prototype.hotSpotPadding_;
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Bounding box.
<a name="line84"></a> *
<a name="line85"></a> * @type {goog.math.Box}
<a name="line86"></a> * @private
<a name="line87"></a> */
<a name="line88"></a>goog.ui.AdvancedTooltip.prototype.boundingBox_;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Anchor bounding box.
<a name="line93"></a> *
<a name="line94"></a> * @type {goog.math.Box}
<a name="line95"></a> * @private
<a name="line96"></a> */
<a name="line97"></a>goog.ui.AdvancedTooltip.prototype.anchorBox_;
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/**
<a name="line101"></a> * Whether the cursor tracking is active.
<a name="line102"></a> *
<a name="line103"></a> * @type {boolean}
<a name="line104"></a> * @private
<a name="line105"></a> */
<a name="line106"></a>goog.ui.AdvancedTooltip.prototype.tracking_ = false;
<a name="line107"></a>
<a name="line108"></a>
<a name="line109"></a>/**
<a name="line110"></a> * Sets margin around the tooltip where the cursor is allowed without dismissing
<a name="line111"></a> * the tooltip.
<a name="line112"></a> *
<a name="line113"></a> * @param {goog.math.Box=} opt_box The margin around the tooltip.
<a name="line114"></a> */
<a name="line115"></a>goog.ui.AdvancedTooltip.prototype.setHotSpotPadding = function(opt_box) {
<a name="line116"></a>  this.hotSpotPadding_ = opt_box || null;
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * @return {goog.math.Box} box The margin around the tooltip where the cursor is
<a name="line122"></a> *     allowed without dismissing the tooltip.
<a name="line123"></a> */
<a name="line124"></a>goog.ui.AdvancedTooltip.prototype.getHotSpotPadding = function() {
<a name="line125"></a>  return this.hotSpotPadding_;
<a name="line126"></a>};
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Sets whether to track the cursor and thereby close the tooltip if it moves
<a name="line131"></a> * away from the tooltip and keep it open if it moves towards it.
<a name="line132"></a> *
<a name="line133"></a> * @param {boolean} b Whether to track the cursor.
<a name="line134"></a> */
<a name="line135"></a>goog.ui.AdvancedTooltip.prototype.setCursorTracking = function(b) {
<a name="line136"></a>  this.cursorTracking_ = b;
<a name="line137"></a>};
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * @return {boolean} Whether to track the cursor and thereby close the tooltip
<a name="line142"></a> *     if it moves away from the tooltip and keep it open if it moves towards
<a name="line143"></a> *     it.
<a name="line144"></a> */
<a name="line145"></a>goog.ui.AdvancedTooltip.prototype.getCursorTracking = function() {
<a name="line146"></a>  return this.cursorTracking_;
<a name="line147"></a>};
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * Sets delay in milliseconds before tooltips are hidden if cursor tracking is
<a name="line152"></a> * enabled and the cursor is moving away from the tooltip.
<a name="line153"></a> *
<a name="line154"></a> * @param {number} delay The delay in milliseconds.
<a name="line155"></a> */
<a name="line156"></a>goog.ui.AdvancedTooltip.prototype.setCursorTrackingHideDelayMs =
<a name="line157"></a>    function(delay) {
<a name="line158"></a>  this.cursorTrackingHideDelayMs_ = delay;
<a name="line159"></a>};
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/**
<a name="line163"></a> * @return {number} The delay in milliseconds before tooltips are hidden if
<a name="line164"></a> *     cursor tracking is enabled and the cursor is moving away from the
<a name="line165"></a> *     tooltip.
<a name="line166"></a> */
<a name="line167"></a>goog.ui.AdvancedTooltip.prototype.getCursorTrackingHideDelayMs = function() {
<a name="line168"></a>  return this.cursorTrackingHideDelayMs_;
<a name="line169"></a>};
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Called after the popup is shown.
<a name="line174"></a> * @protected
<a name="line175"></a> * @suppress {underscore|visibility}
<a name="line176"></a> * @override
<a name="line177"></a> */
<a name="line178"></a>goog.ui.AdvancedTooltip.prototype.onShow_ = function() {
<a name="line179"></a>  goog.ui.AdvancedTooltip.superClass_.onShow_.call(this);
<a name="line180"></a>
<a name="line181"></a>  this.boundingBox_ = goog.style.getBounds(this.getElement()).toBox();
<a name="line182"></a>  if (this.anchor) {
<a name="line183"></a>    this.anchorBox_ = goog.style.getBounds(this.anchor).toBox();
<a name="line184"></a>  }
<a name="line185"></a>
<a name="line186"></a>  this.tracking_ = this.cursorTracking_;
<a name="line187"></a>  goog.events.listen(this.getDomHelper().getDocument(),
<a name="line188"></a>                     goog.events.EventType.MOUSEMOVE,
<a name="line189"></a>                     this.handleMouseMove, false, this);
<a name="line190"></a>};
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Called after the popup is hidden.
<a name="line195"></a> * @protected
<a name="line196"></a> * @suppress {underscore|visibility}
<a name="line197"></a> * @override
<a name="line198"></a> */
<a name="line199"></a>goog.ui.AdvancedTooltip.prototype.onHide_ = function() {
<a name="line200"></a>  goog.events.unlisten(this.getDomHelper().getDocument(),
<a name="line201"></a>                       goog.events.EventType.MOUSEMOVE,
<a name="line202"></a>                       this.handleMouseMove, false, this);
<a name="line203"></a>
<a name="line204"></a>  this.boundingBox_ = null;
<a name="line205"></a>  this.anchorBox_ = null;
<a name="line206"></a>  this.tracking_ = false;
<a name="line207"></a>
<a name="line208"></a>  goog.ui.AdvancedTooltip.superClass_.onHide_.call(this);
<a name="line209"></a>};
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * Returns true if the mouse is in the tooltip.
<a name="line214"></a> * @return {boolean} True if the mouse is in the tooltip.
<a name="line215"></a> */
<a name="line216"></a>goog.ui.AdvancedTooltip.prototype.isMouseInTooltip = function() {
<a name="line217"></a>  return this.isCoordinateInTooltip(this.cursorPosition);
<a name="line218"></a>};
<a name="line219"></a>
<a name="line220"></a>
<a name="line221"></a>/**
<a name="line222"></a> * Checks whether the supplied coordinate is inside the tooltip, including
<a name="line223"></a> * padding if any.
<a name="line224"></a> * @param {goog.math.Coordinate} coord Coordinate being tested.
<a name="line225"></a> * @return {boolean} Whether the coord is in the tooltip.
<a name="line226"></a> * @override
<a name="line227"></a> */
<a name="line228"></a>goog.ui.AdvancedTooltip.prototype.isCoordinateInTooltip = function(coord) {
<a name="line229"></a>  // Check if coord is inside the bounding box of the tooltip
<a name="line230"></a>  if (this.hotSpotPadding_) {
<a name="line231"></a>    var offset = goog.style.getPageOffset(this.getElement());
<a name="line232"></a>    var size = goog.style.getSize(this.getElement());
<a name="line233"></a>    return offset.x - this.hotSpotPadding_.left &lt;= coord.x &amp;&amp;
<a name="line234"></a>        coord.x &lt;= offset.x + size.width + this.hotSpotPadding_.right &amp;&amp;
<a name="line235"></a>        offset.y - this.hotSpotPadding_.top &lt;= coord.y &amp;&amp;
<a name="line236"></a>        coord.y &lt;= offset.y + size.height + this.hotSpotPadding_.bottom;
<a name="line237"></a>  }
<a name="line238"></a>
<a name="line239"></a>  return goog.ui.AdvancedTooltip.superClass_.isCoordinateInTooltip.call(this,
<a name="line240"></a>                                                                        coord);
<a name="line241"></a>};
<a name="line242"></a>
<a name="line243"></a>
<a name="line244"></a>/**
<a name="line245"></a> * Checks if supplied coordinate is in the tooltip, its triggering anchor, or
<a name="line246"></a> * a tooltip that has been triggered by a child of this tooltip.
<a name="line247"></a> * Called from handleMouseMove to determine if hide timer should be started,
<a name="line248"></a> * and from maybeHide to determine if tooltip should be hidden.
<a name="line249"></a> * @param {goog.math.Coordinate} coord Coordinate being tested.
<a name="line250"></a> * @return {boolean} Whether coordinate is in the anchor, the tooltip, or any
<a name="line251"></a> *     tooltip whose anchor is a child of this tooltip.
<a name="line252"></a> * @private
<a name="line253"></a> */
<a name="line254"></a>goog.ui.AdvancedTooltip.prototype.isCoordinateActive_ = function(coord) {
<a name="line255"></a>  if ((this.anchorBox_ &amp;&amp; this.anchorBox_.contains(coord)) ||
<a name="line256"></a>      this.isCoordinateInTooltip(coord)) {
<a name="line257"></a>    return true;
<a name="line258"></a>  }
<a name="line259"></a>
<a name="line260"></a>  // Check if mouse might be in active child element.
<a name="line261"></a>  var childTooltip = this.getChildTooltip();
<a name="line262"></a>  return !!childTooltip &amp;&amp; childTooltip.isCoordinateInTooltip(coord);
<a name="line263"></a>};
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * Called by timer from mouse out handler. Hides tooltip if cursor is still
<a name="line268"></a> * outside element and tooltip.
<a name="line269"></a> * @param {Element} el Anchor when hide timer was started.
<a name="line270"></a> * @override
<a name="line271"></a> */
<a name="line272"></a>goog.ui.AdvancedTooltip.prototype.maybeHide = function(el) {
<a name="line273"></a>  this.hideTimer = undefined;
<a name="line274"></a>  if (el == this.anchor) {
<a name="line275"></a>    // Check if cursor is inside the bounding box of the tooltip or the element
<a name="line276"></a>    // that triggered it, or if tooltip is active (possibly due to receiving
<a name="line277"></a>    // the focus), or if there is a nested tooltip being shown.
<a name="line278"></a>    if (!this.isCoordinateActive_(this.cursorPosition) &amp;&amp;
<a name="line279"></a>        !this.getActiveElement() &amp;&amp;
<a name="line280"></a>        !this.hasActiveChild()) {
<a name="line281"></a>      // Under certain circumstances gecko fires ghost mouse events with the
<a name="line282"></a>      // coordinates 0, 0 regardless of the cursors position.
<a name="line283"></a>      if (goog.userAgent.GECKO &amp;&amp; this.cursorPosition.x == 0 &amp;&amp;
<a name="line284"></a>          this.cursorPosition.y == 0) {
<a name="line285"></a>        return;
<a name="line286"></a>      }
<a name="line287"></a>      this.setVisible(false);
<a name="line288"></a>    }
<a name="line289"></a>  }
<a name="line290"></a>};
<a name="line291"></a>
<a name="line292"></a>
<a name="line293"></a>/**
<a name="line294"></a> * Handler for mouse move events.
<a name="line295"></a> *
<a name="line296"></a> * @param {goog.events.BrowserEvent} event Event object.
<a name="line297"></a> * @protected
<a name="line298"></a> * @override
<a name="line299"></a> */
<a name="line300"></a>goog.ui.AdvancedTooltip.prototype.handleMouseMove = function(event) {
<a name="line301"></a>  var startTimer = this.isVisible();
<a name="line302"></a>  if (this.boundingBox_) {
<a name="line303"></a>    var scroll = this.getDomHelper().getDocumentScroll();
<a name="line304"></a>    var c = new goog.math.Coordinate(event.clientX + scroll.x,
<a name="line305"></a>        event.clientY + scroll.y);
<a name="line306"></a>    if (this.isCoordinateActive_(c)) {
<a name="line307"></a>      startTimer = false;
<a name="line308"></a>    } else if (this.tracking_) {
<a name="line309"></a>      var prevDist = goog.math.Box.distance(this.boundingBox_,
<a name="line310"></a>          this.cursorPosition);
<a name="line311"></a>      var currDist = goog.math.Box.distance(this.boundingBox_, c);
<a name="line312"></a>      startTimer = currDist &gt;= prevDist;
<a name="line313"></a>    }
<a name="line314"></a>  }
<a name="line315"></a>
<a name="line316"></a>  if (startTimer) {
<a name="line317"></a>    this.startHideTimer();
<a name="line318"></a>
<a name="line319"></a>    // Even though the mouse coordinate is not on the tooltip (or nested child),
<a name="line320"></a>    // they may have an active element because of a focus event.  Don&#39;t let
<a name="line321"></a>    // that prevent us from taking down the tooltip(s) on this mouse move.
<a name="line322"></a>    this.setActiveElement(null);
<a name="line323"></a>    var childTooltip = this.getChildTooltip();
<a name="line324"></a>    if (childTooltip) {
<a name="line325"></a>      childTooltip.setActiveElement(null);
<a name="line326"></a>    }
<a name="line327"></a>  } else if (this.getState() == goog.ui.Tooltip.State.WAITING_TO_HIDE) {
<a name="line328"></a>    this.clearHideTimer();
<a name="line329"></a>  }
<a name="line330"></a>
<a name="line331"></a>  goog.ui.AdvancedTooltip.superClass_.handleMouseMove.call(this, event);
<a name="line332"></a>};
<a name="line333"></a>
<a name="line334"></a>
<a name="line335"></a>/**
<a name="line336"></a> * Handler for mouse over events for the tooltip element.
<a name="line337"></a> *
<a name="line338"></a> * @param {goog.events.BrowserEvent} event Event object.
<a name="line339"></a> * @protected
<a name="line340"></a> * @override
<a name="line341"></a> */
<a name="line342"></a>goog.ui.AdvancedTooltip.prototype.handleTooltipMouseOver = function(event) {
<a name="line343"></a>  if (this.getActiveElement() != this.getElement()) {
<a name="line344"></a>    this.tracking_ = false;
<a name="line345"></a>    this.setActiveElement(this.getElement());
<a name="line346"></a>  }
<a name="line347"></a>};
<a name="line348"></a>
<a name="line349"></a>
<a name="line350"></a>/**
<a name="line351"></a> * Override hide delay with cursor tracking hide delay while tracking.
<a name="line352"></a> * @return {number} Hide delay to use.
<a name="line353"></a> * @override
<a name="line354"></a> */
<a name="line355"></a>goog.ui.AdvancedTooltip.prototype.getHideDelayMs = function() {
<a name="line356"></a>  return this.tracking_ ? this.cursorTrackingHideDelayMs_ :
<a name="line357"></a>      goog.ui.AdvancedTooltip.base(this, &#39;getHideDelayMs&#39;);
<a name="line358"></a>};
<a name="line359"></a>
<a name="line360"></a>
<a name="line361"></a>/**
<a name="line362"></a> * Forces the recalculation of the hotspot on the next mouse over event.
<a name="line363"></a> * @deprecated Not ever necessary to call this function. Hot spot is calculated
<a name="line364"></a> *     as neccessary.
<a name="line365"></a> */
<a name="line366"></a>goog.ui.AdvancedTooltip.prototype.resetHotSpot = goog.nullFunction;
</pre>


</body>
</html>
